home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / InsertSuppliers.java < prev    next >
Text File  |  1998-06-30  |  2KB  |  68 lines

  1.  
  2. import java.sql.*;
  3.      
  4. public class InsertSuppliers {
  5.  
  6.     public static void main(String args[]) {
  7.           
  8.       /*****************
  9.       DataTable dt = new JDBCAdapter(
  10.             "jdbc:sybase://dbtest:1455/spring",
  11.             // "SELECT * FROM test",
  12.             "SELECT * FROM COFFEES",
  13.             "connect.sybase.SybaseDriver",
  14.             "guest",
  15.             "trustworthy");
  16.       ****************************/
  17.  
  18.  
  19.         String url = "jdbc:sybase://dbtest:1455/spring";
  20.         Connection con;
  21.         Statement stmt;
  22.         String query = "select SUP_NAME, SUP_ID from SUPPLIERS";
  23.     
  24.         try {
  25.             Class.forName("connect.sybase.SybaseDriver");
  26.     
  27.         } catch(java.lang.ClassNotFoundException e) {
  28.             System.err.print("ClassNotFoundException: ");
  29.             System.err.println(e.getMessage());
  30.         }    
  31.     
  32.         try {
  33.             con = DriverManager.getConnection(url, 
  34.                                      "guest", "trustworthy");
  35.     
  36.             stmt = con.createStatement();                            
  37.     
  38.             stmt.executeUpdate("insert into SUPPLIERS " +
  39.                      "values(49, 'Superior Coffee', '1 Party Place', " +
  40.                  "'Mendocino', 'CA', '95460')");
  41.         
  42.             stmt.executeUpdate("insert into SUPPLIERS " +
  43.                 "values(101, 'Acme, Inc.', '99 Market Street', " +
  44.                 "'Groundsville', 'CA', '95199')");
  45.     
  46.             stmt.executeUpdate("insert into SUPPLIERS " +
  47.                      "values(150, 'The High Ground', '100 Coffee Lane', " +
  48.                  "'Meadows', 'CA', '93966')");
  49.     
  50.             ResultSet rs = stmt.executeQuery(query);
  51.     
  52.             System.out.println("Suppliers and their ID Numbers:");
  53.             while (rs.next()) {
  54.                 String s = rs.getString("SUP_NAME");
  55.                 int n = rs.getInt("SUP_ID");
  56.                 System.out.println(s + "   " + n);
  57.             }
  58.     
  59.             stmt.close();
  60.             con.close();
  61.     
  62.         } catch(SQLException ex) {
  63.             System.err.println("SQLException: " + ex.getMessage());
  64.         }
  65.     }
  66. }
  67.  
  68.